// pages/enterprise/index/user/index.js
import {getRegisterDetail} from "../../../../service/Enterprise";
import {getStorageSync} from "../../../../utils/Storage";
import Config from "../../../../main.config"
Component({

    /*
    * 默认接收全局样式
    * */
    options: {
        addGlobalClass: true
    },

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        _registerInfo: {}
    },

    lifetimes: {
        attached: function () {
            let res = getStorageSync(Config.storage.registerInfo);
            let logoUrl = res.logo ? (Config.api.downLoad + "?fileId=" + res.logo) : null;
            this.setData({
                "_registerInfo.logo": logoUrl,
                "_registerInfo.name": res.name,
                "_registerInfo.nature": res.nature,
                "_registerInfo.scale": res.scale,
                "_registerInfo.industryName": res.industryName
            })
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        /*
        * 获取注册用户信息
        * */
        getRegisterDetail: async function () {
            try {
                let userId = getStorageSync(Config.storage.userInfo + ".userId");
                let res = await getRegisterDetail({createUser: userId});
                let logoUrl = res.logo ? (Config.api.downLoad + "?fileId=" + res.logo) : null;
                this.setData({
                    "_registerInfo.logo": logoUrl,
                    "_registerInfo.name": res.name,
                    "_registerInfo.nature": res.nature,
                    "_registerInfo.scale": res.scale,
                    "_registerInfo.industryName": res.industryName
                })
            } catch (e) {
                console.error(e)
            }
        },

        /*
        * 跳转详情页
        * */
        bindNavigatorToDetail: function () {
            const that = this;
            wx.navigateTo({
                url: "/packageEnterprise/pages/info/index",
                events: {
                    acceptDataFromOpenedPage: function(data) {
                        that.getRegisterDetail();
                    }
                },
            })
        },
    }
})
